# -*- coding:utf-8 -*-
import MySqlCommon
import DateUtil
def getHoliday():
	holidays=[]
	new_holiday=[]
	sql="select start_date,end_date from trip_festival_date_table"
	results=MySqlCommon.query_from_mysql(sql)
	for row in results:
		start_date=str(row[0]).split("-")[0]+str(row[0]).split("-")[1]+str(row[0]).split("-")[2]
		end_date=str(row[1]).split("-")[0]+str(row[1]).split("-")[1]+str(row[1]).split("-")[2]
		holidays+=DateUtil.dateRange(str(start_date), str(end_date))
	return holidays
def getHotDay(productId):
	hotDay=[]
	sql="select date_range from dw_date_table_copy where product_id= '"+productId+"'"
	results = MySqlCommon.query_from_mysql(sql)
	for row in results:
		for range in row[0].split(","):
			start=range.split("-")[0]
			#r是一个数字或者只有月份的日期，根据这个日期生成一个起始的时间，如果只是一个数字则从这个月的第一天开始
			start_date=""
			end_date=""
			if len(start)>2:
				start_date="2017-"+start.split(".")[0]+"-"+start.split(".")[1]
			else:
				start_date="2017-"+start+"-1"
			if len(range.split("-"))>1:
				end=range.split("-")[1]
				if len(end)>2:
					end_date="2017-"+end.split(".")[0]+"-"+end.split(".")[1]
				else:
					end_date="2017-"+end+"-1"
			else:
				end_date="2017-"+start+"-31"
			hotDay+=DateUtil.hotDateRange(str(start_date), str(end_date))
	return hotDay
# holidays=getHoliday()
# if '20170501' in holidays:
# 	print "True"